<script setup lang="ts">
import router from '@/router';

const props = defineProps<{
  title?: string
  rightText?: string
  back?: () => void
}>()
const emit = defineEmits<{
  clickRight: []
}>()
//点击注册触发事件
const clickRight = () => {
  emit('clickRight')
}
//点击左侧按钮触发事件
const clickLeft = () => {
  //弹出层按钮返回原地址
  if (props.back) return props.back()
  //判断有历史记录就跳转历史记录，无记录就跳转首页
  if (history.state.back) {
    router.back()
  } else {
    router.push('/')
  }
}
</script>
<template>
  <van-nav-bar :title=title left-arrow :right-text=rightText fixed @click-right="clickRight" @click-left="clickLeft" />
</template>

<style scoped lang="scss">
:deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }

    &__text {
      font-size: 15px;
    }
  }
}
</style>